import request from '@/config/axios'
import type { Dayjs } from 'dayjs'

/** 班级信息 */
export interface Class {
  id: number // 班级唯一ID
  name?: string // 班级名称
  description: string // 班级描述
  code?: string // 班级口令
  creatorId?: number // 创建者ID
  coverUrl: string // 班级封面图片
  creator: string // 创建者
  createTime: string | Dayjs // 创建时间
  updater: string // 更新者
  updateTime: string | Dayjs // 更新时间
  deleted: boolean // 是否删除
}

// 班级 API
export const ClassApi = {
  // 查询班级分页
  getClassPage: async (params: any) => {
    return await request.get({ url: `/pickbook/classes/page`, params })
  },

  // 查询班级详情
  getClass: async (id: number) => {
    return await request.get({ url: `/pickbook/classes/get?id=` + id })
  },

  // 新增班级
  createClass: async (data: Class) => {
    return await request.post({ url: `/pickbook/classes/create`, data })
  },

  // 修改班级
  updateClass: async (data: Class) => {
    return await request.put({ url: `/pickbook/classes/update`, data })
  },

  // 删除班级
  deleteClass: async (id: number) => {
    return await request.delete({ url: `/pickbook/classes/delete?id=` + id })
  },

  /** 批量删除班级 */
  deleteClassList: async (ids: number[]) => {
    return await request.delete({ url: `/pickbook/classes/delete-list?ids=${ids.join(',')}` })
  },

  // 导出班级 Excel
  exportClass: async (params) => {
    return await request.download({ url: `/pickbook/classes/export-excel`, params })
  }
}
